package com.ruoyi.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysRoles;
import com.ruoyi.system.service.ISysRolesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 角色信息Controller
 * 
 * @author ruoyi
 * @date 2021-10-12
 */
@RestController
@RequestMapping("/system/roles")
public class SysRolesController extends BaseController
{
    @Autowired
    private ISysRolesService sysRolesService;

    /**
     * 查询角色信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:roles:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysRoles sysRoles)
    {
        startPage();
        List<SysRoles> list = sysRolesService.selectSysRolesList(sysRoles);
        return getDataTable(list);
    }

    /**
     * 导出角色信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:roles:export')")
    @Log(title = "角色信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysRoles sysRoles)
    {
        List<SysRoles> list = sysRolesService.selectSysRolesList(sysRoles);
        ExcelUtil<SysRoles> util = new ExcelUtil<SysRoles>(SysRoles.class);
        return util.exportExcel(list, "角色信息数据");
    }

    /**
     * 获取角色信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:roles:query')")
    @GetMapping(value = "/{rolesId}")
    public AjaxResult getInfo(@PathVariable("rolesId") Long rolesId)
    {
        return AjaxResult.success(sysRolesService.selectSysRolesByRolesId(rolesId));
    }

    /**
     * 新增角色信息
     */
    @PreAuthorize("@ss.hasPermi('system:roles:add')")
    @Log(title = "角色信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysRoles sysRoles)
    {
        return toAjax(sysRolesService.insertSysRoles(sysRoles));
    }

    /**
     * 修改角色信息
     */
    @PreAuthorize("@ss.hasPermi('system:roles:edit')")
    @Log(title = "角色信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysRoles sysRoles)
    {
        return toAjax(sysRolesService.updateSysRoles(sysRoles));
    }

    /**
     * 删除角色信息
     */
    @PreAuthorize("@ss.hasPermi('system:roles:remove')")
    @Log(title = "角色信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rolesIds}")
    public AjaxResult remove(@PathVariable Long[] rolesIds)
    {
        return toAjax(sysRolesService.deleteSysRolesByRolesIds(rolesIds));
    }
}
